package com.ailk.tcm.activity;

import net.tsz.afinal.core.Arrays;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

import com.ailk.tcm.R;
import com.ailk.tcm.hffw.android.common.MyApplication;
import com.ailk.tcm.hffw.android.common.ui.pagerAdapter.ViewPagerAdapter;
import com.viewpagerindicator.PageIndicator;

public class EntranceActivity extends Activity implements OnClickListener{
	
	private ViewPager viewPager;
	private PageIndicator pageIndicator;
	private Button registerBtn;
	private Button loginBtn;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyApplication.getInstance().onActivityCreate(this);
		setContentView(R.layout.activity_entrance);
		viewPager = (ViewPager) findViewById(R.id.view_pager);
		pageIndicator = (PageIndicator) findViewById(R.id.page_indicator);
		registerBtn = (Button) findViewById(R.id.btn_register);
		loginBtn = (Button) findViewById(R.id.btn_login);
		
		registerBtn.setOnClickListener(this);
		loginBtn.setOnClickListener(this);
		generatePages();
	}
	
	private void generatePages(){
		ImageView iv1 = new ImageView(this);
		iv1.setScaleType(ScaleType.FIT_CENTER);
		iv1.setImageResource(R.drawable.ic_launcher);
		
		ImageView iv2 = new ImageView(this);
		iv2.setScaleType(ScaleType.FIT_CENTER);
		iv2.setImageResource(R.drawable.ic_launcher);
		
		viewPager.setAdapter(new ViewPagerAdapter(Arrays.asList(iv1, iv2), null));
		pageIndicator.setViewPager(viewPager);
	}

	@Override
	protected void onDestroy() {
		MyApplication.getInstance().onActivityDestroy(this);
		super.onDestroy();
	}

	@Override
	protected void onResume() {
		MyApplication.getInstance().onActivityResume(this);
		super.onResume();
	}

	@Override
	protected void onStop() {
		MyApplication.getInstance().onActivityStop(this);
		super.onStop();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_register:
			
			break;

		case R.id.btn_login:
			Intent loginIntent = new Intent(this, MainActivity.class);
			startActivity(loginIntent);
			break;
		}
	}
	
}
